# -*- coding:utf-8 -*-
__author__ = 'Forcs'

from wanbatvcom.utils import jsonable

'''
    响应数据结果的基类
'''
class ResponseResult(jsonable.Jsonable):

    __status_code = 0   # 响应状态码，0：是吧，1：成功，int
    __message = ''      # 响应消息，string
    _data = jsonable.Jsonable()    # 数据，{}

    def __init__(self, status_code, message, data={}):
        self.__status_code = status_code
        self.__message = message
        self.set_data(data)

    # 获取状态码
    def get_status_code(self):
        return self.__status_code

    # 获取消息
    def get_message(self):
        return self.__message

    # 获取数据
    def get_data(self):
        return self._data

    # 设置数据
    def set_data(self, data):
        self._data = data
        self._on_bind_data(data)

    '''
    将对象的属性值转成JSON
    '''
    def to_json(self):
        result = dict()
        result['status_code'] = self.__status_code
        result['message'] = self.__message
        data = self._data.to_json
        if not data:
            result['data'] = data
        return result

    def from_json(self, json):
        pass

    def _on_bind_data(self, data):
        pass
